/*
 * Time-stamp: <18 Jul 2006 11:55 BST tifflib.h km> 
 * Copyright (c) Solexa 2004, 2005, 2006
 * Author:
 * Klaus Maisinger
 * This source file is covered by the "Solexa Public Source License"
 * agreement and bound by the terms therein.
 */

#ifndef _TIFFLIB_H
#define _TIFFLIB_H


/* TIFF tags used by Manteia */
#define TIFFTAG_MANTEIA_GENOPSYS_HEADER	        65012
#define TIFFTAG_MANTEIA_IMAGE_TEMPERATURE	65013
#define TIFFTAG_MANTEIA_LIGHTDOSE		65014
#define TIFFTAG_MANTEIA_LIGHTDOSE_PERCENT	65015
#define TIFFTAG_MANTEIA_Z_FOCUS_POSITION	65016
#define TIFFTAG_MANTEIA_CAMERA_GAIN		65017
#define TIFFTAG_MANTEIA_X_STAGE_POSITION	65018
#define TIFFTAG_MANTEIA_Y_STAGE_POSITION	65019
#define TIFFTAG_MANTEIA_EXPOSURE_TIME		65020
#define TIFFTAG_MANTEIA_BINNING			65021
#define TIFFTAG_MANTEIA_FLUO			65022
#define TIFFTAG_MANTEIA_HALOGEN			65023
#define TIFFTAG_MANTEIA_SHOOTTIME		65024
#define TIFFTAG_MANTEIA_USERNAME		65025

/* TIFF tags reserved for MetaMorph */
#define TIFFTAG_UIC1TAG 33628
#define TIFFTAG_UIC2TAG 33629
#define TIFFTAG_UIC3TAG 33630
#define TIFFTAG_UIC4TAG 33631

/* MetaMorph tag IDs */
#define UICTAG_AUTOSCALE 0      /* long */
#define UICTAG_MINSCALE 1
#define UICTAG_MAXSCALE 2
#define UICTAG_SPATIALCALIBRATION 3
#define UICTAG_XCALIBRATION 4   /* float */
#define UICTAG_YCALIBRATION 5
#define UICTAG_CALIBRATIONUNITS 6       /* offset of long, string */
#define UICTAG_NAME 7           /* offset of long, string */
#define UICTAG_THRESHSTATE 8    /* long */
#define UICTAG_THRESHSTATERED 9
#define UICTAG_THRESHSTATEGREEN 11
#define UICTAG_THRESHSTATEBLUE 12
#define UICTAG_THRESHSTATELO 13
#define UICTAG_THRESHSTATEHI 14
#define UICTAG_ZOOM 15
#define UICTAG_CREATETIME 16    /* offset of long (date), long (time) */
#define UICTAG_LASTSAVEDTIME 17
#define UICTAG_CURRENTBUFFER 18 /* long */
#define UICTAG_GRAYX 21         /* float */
#define UICTAG_GRAYY 22
#define UICTAG_GRAYMIN 23
#define UICTAG_GRAYMAX 24
#define UICTAG_GRAYUNITNAME 25  /* offset of long, string */
#define UICTAG_STANDARDLUT 26   /* long (lookup table state?) */
#define UICTAG_STAGEPOSITION 28 /* offset 4*LONG (*N) */
#define UICTAG_CAMERACHIPOFFSET 29
#define UICTAG_IMAGEPROPERTY 36 /* offset of user-defined property */
#define UICTAG_STAGELABEL 37    /* offset of table of long, string */
#define UICTAG_AUTOSCALELOINFO 38       /* float */
#define UICTAG_AUTOSCALEHIINFO 39
#define UICTAG_ABSOLUTEZ 40     /* offset of table of N floats */
#define UICTAG_ABSOLUTEZVALID 41        /* offset of table of longs */
#define UICTAG_GAMMA 42         /* offset of long */
#define UICTAG_GAMMARED 43
#define UICTAG_GAMMAGREEN 44
#define UICTAG_GAMMABLUE 45

/* MetaMorph tags for userdefined properties */
#define UICTAG_FLOAT 1
#define UICTAG_ASCII 2


#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include "tiff.h"

    struct tiff_file {
        FILE *file_stream;
        int little_endian;
        uint16 ifd_len;
        TIFFDirEntry *ifd_table;
        int cacheflag;
        uint8 *data;
        long data_length;
        long data_pointer;
        struct tiff_file *next_file;
    };

    typedef struct tiff_file TIFF_FILE;

    TIFF_FILE *fopen_tiff(const char *path, const char *mode, int mem);
    int fclose_tiff(TIFF_FILE * stream);
    int fget_tiff_size(TIFF_FILE * fp, int *nx, int *ny, int *ns);
    int fget_tiff_data(TIFF_FILE * fp, unsigned short *buffer, long len,
                       long offset);
    int fget_tiff_image_description(TIFF_FILE * fp, char description[], int len);

    int fget_tiff_field_uint16(TIFF_FILE * fp, unsigned short tag,
                               unsigned short *result);
    int fget_tiff_field_uint32(TIFF_FILE * fp, unsigned short tag,
                               unsigned int *result);
    int fget_tiff_field_string(TIFF_FILE * fp, unsigned short tag,
                               char **description);
    int fget_tiff_field_float(TIFF_FILE * fp, unsigned short tag,
			      float *result);
    int fget_tiff_field_double(TIFF_FILE * fp, unsigned short tag,
			       double *result);
    int fget_tiff_image_string_property(TIFF_FILE * fp, char property[],
                                        char **value);
    int fget_tiff_image_float_property(TIFF_FILE * fp, char property[],
                                       float *value);
    int fget_tiff_uic1_long_field(TIFF_FILE * fp, unsigned int tag,
                                  unsigned int *value);
    int fget_tiff_uic1_longs_field(TIFF_FILE * fp, unsigned int tag,
                                   unsigned int *values, int nval);
    int fget_tiff_uic4_longs_field(TIFF_FILE * fp, unsigned short tag,
                                   unsigned int *values, int nval);
    int fget_tiff_uic1_float_field(TIFF_FILE * fp, unsigned int tag,
				   float *value);


#if defined(HAVE_LIBTIFF)
    int fwrite_tiff_image(char filename[], void *data,
                          int nx, int ny, int bytesperpixel,
                          char description[]);
#endif                          /* HAVE_TIFFLIB */

#ifdef __cplusplus
}
#endif
#endif
